#pragma once

#include "math.h"
#include "IDomain2.h"



/** @todo share implementation with MinkowskiSum2  */
class MinkowskiSum2 : public IConvexDomain2
{
public:
	//for collision detection
	class InternalPoint
	{
	public:
		InternalPoint();
		InternalPoint(const MinkowskiSum2& difference);
		const Vector2 point() const	{	return point_;	}
		const Vector2 pointOn1() const	{	return pointOn1_;	}
		const Vector2 pointOn2() const	{	return pointOn2_;	}

	private:
		Vector2 pointOn1_;
		Vector2 pointOn2_;
		Vector2 point_;
	};

	class SupportPoint
	{
	public:
		SupportPoint();
		SupportPoint(const MinkowskiSum2& sum, const Vector2& normal);
		const Vector2 normal() const	{	return point_;	}
		const Vector2 point() const	{	return point_;	}
		const Vector2 pointOn1() const	{	return pointOn1_;	}
		const Vector2 pointOn2() const	{	return pointOn2_;	}

	private:
		Vector2 normal_;
		Vector2 pointOn1_;
		Vector2 pointOn2_;
		Vector2 point_;
	};

public:
	MinkowskiSum2(const IConvexDomain2& p1, const Vector2& t1, const IConvexDomain2& p2, const Vector2& t2);
	virtual const Vector2 internalPoint() const;
	void internalPointEx(InternalPoint& result) const;
	virtual const Vector2 supportPoint(const Vector2& normal) const;
	void supportPointEx(const Vector2& normal, SupportPoint& supportPoint) const;

private:
	friend class SupportPoint;

	const IConvexDomain2*	p1;
	const Vector2*			t1;
	const IConvexDomain2*	p2;
	const Vector2*			t2;
};

////////////////////////////////////////////////////////////////////////

#include "Convolution2.h"
class IExplicitBounded2;
class IImplicitBounded2;
class IStackAllocator;


/** specialzation for polygonal shape. 
 *  @warning don't use this class.  this is @em test implementationunder construntion.
 */
class MinkowskiSumExIm2 : public IBounded2
{
public:
	MinkowskiSumExIm2(
		const IExplicitBounded2& domainA, const Vector2& tA,
		const IImplicitBounded2& domainB, const Vector2& tB);

	virtual const Vector2 internalPoint() const;
	virtual const Vector2 supportPoint(const Vector2& normal) const;

	/**
	 @note minkowski sum of convex shapes are bounded by convolution of the boundaries of the each shape.
	*/
	ConvolutionExIm2* boundary(IStackAllocator& stack) const; 

private:
	const IExplicitBounded2* domainA_;
	const Vector2* tA_;
	const IImplicitBounded2* domainB_;
	const Vector2* tB_;

};

